
<div class="content margin_top">
    <header class="header fixed_top bg_mx_green"></header>
    <div class="bg_mx_green padding_15" style="padding-top:0;">
        <div class="bg_white padding_10_15 color_black font_16 room"></div>
    </div>
    <div class="bg_white margin_b_15">
        <div class="padding_15 v_center border_b">
            <div class="width_70">总分</div>
            <div class="left_100 font_20 grey">
                <i class="iconfont icon-star1 padding_5"></i>
                <i class="iconfont icon-star1 padding_5"></i>
                <i class="iconfont icon-star1 padding_5"></i>
                <i class="iconfont icon-star1 padding_5"></i>
                <i class="iconfont icon-star1 padding_5"></i>
            </div>
            <div class="width_30"><span class="score">0</span>分</div>
        </div>
        <div class="padding_15">
            <textarea name="conmment" placeholder="感觉如何呢？（听说写够15字，会变美哦~）" rows="5" request title="评价内容"></textarea>
        </div>
    </div>
    <div class="padding_15 bg_white margin_b_10">
        <div class="preview0 flex_row_3 margin_b_10" style="display:none;"></div>
        <div class="light lineheight_3 v_center input0">
            <div class="width_50 border text_center relative">
                <div class="iconfont icon-add font_20"></div>
                <input class="absolute all" type="file" value="" accept="image/*" style="opacity:0;" onchange="selectpic(this)"/>
            </div>
            <div class="left_50  padding_l_15">点击上传图片</div>
        </div>
    </div>
    <input name="_csrf" type="hidden" id="_csrf" value="<{$app->request->csrfToken}>">
    <input name="hid" type="hidden" id="hid" value="<{$app->request->get('hid')}>">
    <input name="oid" type="hidden" id="oid" value="<{$app->request->get('oid')}>">
    <div class="padding_15 font_16">
        <button class="btn btn_mx_green all_width lineheight_3" onclick="save()">保存</button>
    </div>
</div>
<div class="toast"></div>
<!-- toast模版 -->
<script type="text/template" charset="utf-8" id='toast_template'>
    <i class="iconfont icon-toast{{=it.icon}}"></i>
    <div class="toast_text">{{=it.text}}</div>
</script>
<script type="text/template" id='room_template'>
    <div>{{=it.title}}</div>
    <div class="font_14 danger">{{=it.content}}</div>
</script>
<script type="text/template" charset="utf-8" id='img_template'>
    {{for(var i=0;i<it.length;i++){}}
    <div class="row_one relative">
        <div class="del_img" onclick="del(this,{{=i}})">&times;</div>
        <img class="all_height" src="{{=it[i]}}">
    </div>
    {{}}}
</script>
<script>
    // 页面初始化
//    var room = {title:"鲜美的后腿肉",content:"￥20.00元/份"};
    var room = <{$house}>;
    var evalroom = doT.template($("#room_template").text());
    var evalToast = doT.template($("#toast_template").text());
    loaddata(".room",evalroom,room);
    loadheadbar("商品评价");
    // 评分
    $(".icon-star1").click(function(){
        $(this).addClass("warning").siblings().removeClass("warning")
        $.each($(".icon-star1"),function(k,v){
            $(".score").html(k+1)
            if($(v).hasClass("warning")){
                return false
            }
            $(v).addClass("warning")
        })
    })
    // 选择图片
    var img_arr=[],imgs=[],evalImg = doT.template($("#img_template").text());
    function selectpic(obj){
        var file = obj.files[0];
        var URL = window.URL || window.webkitURL;
        tobase64(file,function(res){
            imgs.push(res);
        })
        img_arr.push(URL.createObjectURL(file))
        $(obj).val("");
        $(".preview0").show().html(evalImg(img_arr));
        if(img_arr.length>=3){
            $(".input0").hide();
        }
    }
    // 删除图片
    function del(obj,i){
        imgs.splice(i,1);
        img_arr.splice(i,1);console.log(img_arr)
        if(img_arr.length){
            $(".preview0").html(evalImg(img_arr));
        }else{
            $(".preview0").hide()
        }
        $(".input0").show();
    }
    // 提交表单
    var submited = false;
    function save(){
        var ele = $("textarea[name='conmment']");
        if(!$(".icon-star1.warning").length){
            toast("wrong","请选择星星打分");
            return false;
        }
        if(!ele.val()){
            toast("wrong","请输入"+ele.attr("title"));
            ele.focus();
            return false;
        }
        if(submited) return false;
        $.post("/farmerhouse/site/post-comment",{score:$(".score").html(),conmment:ele.val(),img:imgs.join("%^"),hid:$('#hid').val(),_csrf:$('#_csrf').val(),oid:$('#oid').val()},function(res){
            toast("attention",res.msg);
            submited = true;
            if(res.status == 0){
                location.href='/business/user/farmer-house-order/index?status=3'
            }
        },"json");
    }
</script>

